package com.jn.exam.exceptionHandler;

import com.jn.exam.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 江南大学1033190417
 * @date 2022/1/5 18:46
 */
@ControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        log.error(e.getMessage());
        return R.error().message(e.getMessage());
    }

    //自定义异常
    @ExceptionHandler(ExamException.class)
    @ResponseBody
    public R error(ExamException e){
        log.error(e.getMessage());
        return R.error().code(e.getCode()).message(e.getMsg());
    }
}
